package com.chen.controller.user;

import com.chen.pojo.entity.User;
import com.chen.pojo.vo.SystemInfo;
import com.chen.pojo.vo.UserVo;
import com.chen.results.Result;
import com.chen.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/admins/")
@RequiredArgsConstructor
@Api(tags = "管理员接口管理")
@Slf4j
public class AdminController {
    private final UserService userService;

    // 获取系统系统统计信息
    @GetMapping("info")
    @ApiOperation("管理员用户获取系统信息")
    public Result<SystemInfo> getSystemInfo() {
        SystemInfo systemInfo = userService.getSystemInfo();
        return Result.success(systemInfo);
    }

    // 获取所有用户信息
    @PostMapping("allUser")
    @ApiOperation("管理员获取所有的用户信息")
    public Result<List<UserVo>> getAllUsers(HttpServletRequest request) {
        List<UserVo> userVoList = userService.getAllUsers();
        return Result.success(userVoList);
    }

    // 管理员添加一个用户
    @PostMapping
    @ApiOperation("管理员添加一个用户")
    public Result<UserVo> saveUser(@Validated @RequestBody User user) {
        log.info("新增的用户的信息：{}", user);
        UserVo vo = userService.saveUser(user);
        return Result.success(vo);
    }


    // 禁用用户 管理员
    // del

    // put
    @PutMapping("disabled/{id}")
    @ApiOperation("禁用用户")
    public Result<UserVo> disabledUserById(@PathVariable("id") Long id) {
        log.info("禁用。的用户的id为：{}", id);
        UserVo vo = userService.disabledUserById(id);
        return Result.success(vo);
    }


    // 启用用户 管理员
    @PutMapping("enabled/{id}")
    @ApiOperation("启用用户")
    public Result<UserVo> enabledUserById(@PathVariable("id") Long id) {
        log.info("启用的用户的id为：{}", id);
        UserVo vo = userService.enabledUserById(id);
        return Result.success(vo);
    }


    @DeleteMapping("{id}")
    @ApiOperation("管理员删除用户")
    public Result deleteUserById(@PathVariable Long id) {
        userService.deleteUserById(id);
        return Result.success();
    }


}
